<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    table {
        width: 500px;
        margin: 100px auto;
        border-collapse: collapse;
        text-align: center;
    }
    
    td,
    th {
        border: 1px solid #333;
    }
    
    thead tr {
        height: 40px;
        background-color: #ccc;
    }
</style>

<body>
    <table cellspacing="0">
        <thead>
            <tr>
                <th>姓名</th>
                <th>科目</th>
                <th>成绩</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
    <script>
        //1.添加数据
        var datas = [{
                name: '景玉龙',
                subject: '大数据',
                score: 100
            }, {
                name: '景玉龙',
                subject: 'C#',
                score: 100
            }, {
                name: '景玉龙',
                subject: '专业实习',
                score: 100
            }, {
                name: '岁超凡',
                subject: '大数据',
                score: 98
            }, {
                name: '岁超凡',
                subject: 'C#',
                score: 100
            }, {
                name: '岁超凡',
                subject: '专业实习',
                score: 100
            }, {
                name: '商烁',
                subject: '大数据',
                score: 98
            }, {
                name: '商烁',
                subject: 'C#',
                score: 100
            }, {
                name: '商烁',
                subject: '专业实习',
                score: 100
            }, {
                name: '杨启祥',
                subject: '大数据',
                score: 98
            }, {
                name: '杨启祥',
                subject: 'C#',
                score: 100
            }, {
                name: '杨启祥',
                subject: '专业实习',
                score: 100
            }, {
                name: '大猪蹄子',
                subject: '大数据',
                score: 98
            }, {
                name: '大猪蹄子',
                subject: 'C#',
                score: 100
            }, {
                name: '大猪蹄子',
                subject: '专业实习',
                score: 100
            }, ]
            // 2.往tbody里面添加行
        var tbody = document.querySelector('tbody');
        for (var i = 0; i < datas.length; i++) {
            //创建行tr
            var tr = document.createElement('tr');
            tbody.appendChild(tr);
            // 在行里创建列
            for (var k in datas[i]) {
                var td = document.createElement('td');
                // 把对象里面的属性值给td
                // for(var k in obj) {
                //     k 得到的是属性名
                //     obj[k] 得到是属性值
                // }
                td.innerHTML = datas[i][k];
                tr.appendChild(td);
            }
            // 3.创建有删除两个字的单元格
            var td = document.createElement('td');
            td.innerHTML = '<a href = "javascript:;">删除</a>';
            tr.appendChild(td);
        }
        // 4.删除操作
        var tt = document.querySelectorAll('a');
        for (var i = 0; i < tt.length; i++) {
            tt[i].onclick = function() {
                tbody.removeChild(this.parentNode.parentNode)
            }
        }
    </script>
</body>

</html>